﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using QLibrary.Engine;
using System.Collections.Generic;
using QModel;
using Newtonsoft.Json.Linq;

namespace QService.Parser
{
    public class FeedsParser : QParser
    {
        public override void ParseJson(string json, Dictionary<string, object> resultData)
        {
            if (!string.IsNullOrEmpty(json) && resultData.ContainsKey("FeedsList"))
            {
                List<FeedsEntity> feedsList = resultData["FeedsList"] as List<FeedsEntity>;
                JArray jarray = JArray.Parse(json);
                foreach (JToken jtoken in jarray )
                {
                    FeedsEntity feedsEntity = new FeedsEntity();
                    feedsEntity.ActorId = jtoken["actor_id"].ToString();
                    feedsEntity.ActorType = jtoken["actor_type"].ToString();
                    feedsEntity.SourceId = jtoken["source_id"].ToString();
                    feedsEntity.FeedType = jtoken["feed_type"].ToString();
                    feedsEntity.PostId = jtoken["post_id"].ToString();
                    feedsEntity.HeadUrl = jtoken["headurl"].ToString();
                    feedsEntity.Title = jtoken["title"].ToString();
                    feedsEntity.UpdateTime = jtoken["update_time"].ToString();
                    feedsEntity.Message = jtoken.Value<string>("message");
                    feedsEntity.Description = jtoken.Value<string>("description");
                    feedsEntity.Name = jtoken.Value<string>("name");
                    feedsEntity.Prefix = jtoken.Value<string>("prefix");
                    feedsList.Add(feedsEntity);
                }
            }
            if (this._nextParser != null)
            {
                this._nextParser.ParseJson(json, resultData);
            }
        }
    }
}
